﻿
namespace FacebookXmpp.Parse
{
	internal class XmlElementInner : XmlParseState
    {
        public XmlElementInner(XmlParseState from)
            : base(from)
        { }

        public override XmlParseState Parse(StringParser parser)
        {
            if (parser.PauseIfNearEnd(2))
                return this;

            // Closing "</name>"
			if (parser.IsNext( "</" ))
				return new XmlCloseElement(this);

            // Sub xml "<bla...."
            if (parser.IsNext("<"))
            {
            	_builder.StartElement();
                return new XmlStartElement(this);
            }

            int index = parser.Find("<");
            if (index == -1)
            {
                parser.Pause();
                return this;
            }
			_builder.Current.Value = parser.ConsumeTo( index );

            return this;
        }
    }
}